#include "printlog.h"


printLog::printLog()
{
    filepath = "C:\\log";
    QDir dir(filepath);
    if (!dir.exists())
    {
        dir.mkdir(filepath);
    }
    QDate date ;
    QString day = date.currentDate().toString("yyyyMMdd");
    QTime time ;
    timer = time.currentTime().toString("hh:mm:ss");
    filepath.append("\\");
    filepath.append(day);
    filepath.append(".txt");
    file.setFileName(filepath);
    if (file.open(QIODevice::ReadWrite))
    {
        stream.setDevice(&file);
        stream.seek(file.size());
    }
}

printLog::~printLog()
{
    file.close();
}

void printLog::logprint(QString str)
{
    stream << "\n"<<timer<<":";
    stream << "\n\t" << str ;
}

void printLog::logprint(QByteArray str)
{
    stream << "\n"<<timer<<":";
    stream << "\n\t" << QString(str) ;
}

void printLog::logprint(QString str1, QString str2)
{
    stream << "\n" <<timer << ":" ;
    stream << "\n\t" << str1 <<" : " << str2 ;
}

void printLog::logprint(QByteArray str1, QByteArray str2)
{
    stream << "\n" <<timer << ":" ;
    stream << "\n\t" << str1 <<" : " << str2 ;
}

void printLog::closefile()
{
    file.close();
}
